package hc.server.ui.design;

import hc.server.ui.ICanvas;
import hc.server.ui.design.hpj.HCjar;

import java.util.Map;

public class JarMainMenu extends MCanvasMenu implements ICanvas {
	public final String[][] items;
	public static final int itemColNum = 3;
	private final String menuName;
	public final String menuId;
	public final String[] listener;
	
	public static final int ITEM_NAME_IDX = 0;
	public static final int ITEM_IMG_IDX = 1;
	public static final int ITEM_URL_IDX = 2;
	
	public JarMainMenu(int menuIdx, Map map) {
		menuName = (String)map.get(HCjar.replaceIdxPattern(HCjar.MENU_NAME, menuIdx));
		menuId = (String)map.get(HCjar.replaceIdxPattern(HCjar.MENU_ID, menuIdx));
		Object menuItemObj = map.get(HCjar.replaceIdxPattern(HCjar.MENU_CHILD_COUNT, menuIdx));
		if(menuItemObj != null){
			final int itemCount = Integer.parseInt((String)menuItemObj);
			items = new String[itemCount][itemColNum];
			listener = new String[itemCount];
			final String Iheader = HCjar.replaceIdxPattern(HCjar.MENU_ITEM_HEADER, menuIdx);
			for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
				String header = Iheader + itemIdx + ".";
				
				items[itemIdx][0] = (String)map.get(header + "Name");
//				Integer.parseInt((String)map.get(header + "Type")
				items[itemIdx][1] = (String)map.get(header + "Image");
				items[itemIdx][2] = (String)map.get(header + "Url");
				
				listener[itemIdx] = (String)map.get(header + "Listener"); 
			}
		}else{
			items = new String[0][itemColNum];
			listener = new String[0];
		}
	}
	
	public String[] getIconLabels() {
		String[] out = new String[items.length];
		for (int i = 0; i < out.length; i++) {
			out[i] = items[i][ITEM_NAME_IDX];
		}
		return out;
	}

	public String[] getIcons() {
		String[] out = new String[items.length];
		for (int i = 0; i < out.length; i++) {
			out[i] = items[i][ITEM_IMG_IDX];
		}
		return out;
	}

	public short getNumCol() {
		return 0;//自动计算itemColNum;
	}

	public short getNumRow() {
		return (short)(items.length/3 + 1);
	}

	public short getSize() {
		return (short)items.length;
	}

	public String getTitle() {
		return menuName;
	}

	public String[] getURLs() {
		String[] out = new String[items.length];
		for (int i = 0; i < out.length; i++) {
			out[i] = items[i][ITEM_URL_IDX];
		}
		return out;
	}

	public boolean isFullMode() {
		return false;
	}

	@Override
	public void onStart() {
	}

	@Override
	public void onPause() {
	}

	@Override
	public void onResume() {
	}

	@Override
	public void onExit() {
	}

}
